package org.dea.facade;

import java.io.File;

import org.dea.util.SourceUtil;

import de.gulden.util.javasource.Class;

public class RMIInterfaceFacadeMaker implements FacadeMaker{
	
	public static final String IF_PREFIX = "IF";

	public Class generateFacade(File sourceDir, String fullQualifiedName) throws Exception{
		Class baseClass = SourceUtil.loadClassSource(sourceDir, fullQualifiedName);
		if( baseClass == null )
			throw new RuntimeException("Class "+fullQualifiedName+" does not exist on sourceDir "+ sourceDir);
		Class rmiIF = SourceUtil.extractInterface(baseClass, IF_PREFIX+baseClass.getUnqualifiedName());
		SourceUtil.changeSuperClass(rmiIF, "Remote");
		SourceUtil.changeSuperClass(rmiIF, "DistributedEasyAcceptFacade");
		SourceUtil.addExceptionAllMethods(baseClass, "RemoteException" );
		SourceUtil.addImport(rmiIF, "java.rmi", "*");
		SourceUtil.addImport(rmiIF, "org.dea.interfaces", "*");
		SourceUtil.generateSourceFile(sourceDir, rmiIF);
		return rmiIF;
	}


	
	public static void main(String[] args) throws Exception {
//		new AllFacadesMaker("test/xml/onlyAlpha.xml").generateFacade(new File("test"), "somepack.Simple");
		new RMIInterfaceFacadeMaker().generateFacade(new File("test"), "somepack.innerpack.Simple");
	}

}
